<template>
    <div class="container">
        <el-row class="wrap-search">
            <span class="export-span" v-if = "multipleSelection.length != 0">
                <form :action="url" method="get" >
                    <button class="export" type="submit">批量导出</button>
                    <input type="hidden" name="idIn"  :value="multipleSelection" />
                    <input type="hidden" name="talentNameLike"  :value="configList.param.talentNameLike" />
                    <input type="hidden" name="orderNoLike"  :value="configList.param.orderNoLike" />
                    <input type="hidden" name="orderStatus"  :value="configList.param.orderStatus" />
                    <input type="hidden" name="pageSize"  :value="1000" />
                </form>
            </span>
            <span  class="export-span" v-else>
                <button class="export" type="submit" @click="check">批量导出</button>
                <input type="hidden" name="ids" :value="multipleSelection" />
            </span>
        </el-row>
        <el-row class="wrap-search">
            <div class="search-item">
                <div class="search-title">人才姓名查询：</div>
                <el-input style="width: 200px;" class=""
                          placeholder="请输入关键字"
                          v-model="configList.param.talentNameLike" ></el-input>
            </div>
            <div class="search-item">
                <div class="search-title">订单编号：</div>
                <el-input style="width: 200px;" class=""
                          placeholder="请输入关键字"
                          v-model="configList.param.orderNoLike" ></el-input>
            </div>
            <el-button  class="search-btn" type="primary" @click="getList()">查询</el-button>
        </el-row>
        <div class="">
            <table-list ref="tableList" :tableConfig='configList' @selectTable="selectTable">
                <el-table-column
                        slot="select"  align="center" label="全选"
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column slot="sex"  align="center" label="性别">
                    <template slot-scope="scope">
                        <div v-if="scope.row.sex == 'female'">女性</div>
                        <div v-else-if="scope.row.sex=='male'">男性</div>
                        <div v-else>未知</div>
                    </template>
                </el-table-column>
                <el-table-column class="btn"  min-width="240px" label="操作" slot="btn" align="center" >
                    <template slot-scope="scope">
                        <el-button  @click="submitSign(scope.row.id)" type="primary" size="small">确认签约</el-button>
                        <el-button  @click="submitRefund(scope.row.id)" type="primary" size="small">可退全款</el-button>
                        <el-button  @click="$router.push('/orderDetail?id='+scope.row.id)" type="primary" size="small">查看</el-button>
                    </template>
                </el-table-column>
            </table-list>
        </div>
        <el-dialog
                title="批量导入"
                :visible.sync="dialogVisible"
                size="tiny"
        >
            <div>
                <div>注意事项</div>
                <ul>
                    <li>1.导入的数据文件必须为可识别的Excel文件，后缀名为.xls，且文件大小不多于2M。</li>
                    <li>2.不可导入已有的信息。</li>
                    <li>3.Excel表字段格式必须和后台字段保持一致。</li>
                </ul>
                <el-upload
                        class="upload-demo"
                        ref="upload"
                        action="https://jsonplaceholder.typicode.com/posts/"
                        :on-preview="handlePreview"
                        :on-remove="handleRemove"
                        :file-list="fileList"
                        :auto-upload="false">
                    <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                    <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传</el-button>
                </el-upload>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    let CONSTANT = require('../../constant/constant.js');
    let common = require("../../common.js");
    export default {
        data() {
            return {
                url: '',
                configList:{
                    url:CONSTANT.URL.ORDER.LIST,
                    configList:[
                        {
                            slot: "select"
                        },
                        {
                            label:'订单编号',
                            prop:'orderNo',
                        },
                        {
                            label: "实付金额",
                            prop: "payAmount"
                        },
                        {
                            label:'订单状态',
                            prop:'orderStatusText',
                        },
                        {
                            label:'人才姓名',
                            prop:'talentName',
                        },
                        {
                            label:'预定人',
                            prop:'userName',
                        },
                        {
                            label:'人才分类',
                            prop:'talentCategory',
                        },
                        {
                            label:'推荐费付款时间',
                            prop:'orderTime',
                        },
                        {
                            slot:'btn'
                        }
                    ],
                    param:{
                        orderStatus: "un_sign",
                        orderNoLike: "",
                        talentNameLike: "",
                    },
                    type:'',
                    width:'',
                    isPagination:true
                },
                dialogVisible:false,
                imgUrl:'',
                upLoadUrl:'',
                dataList:[],
                provinceList:[],
                cityList:[],
                statusArr:{
                    'on':'上架',
                    'off':'下架'
                },
                statusArrList:[
                    {
                        item:'',
                        value:'全部'
                    },
                    {
                        item:'ing',
                        value:'众筹中'
                    },
                    {
                        item:'success',
                        value:'众筹成功'
                    },
                    {
                        item:'fail',
                        value:'众筹失败'
                    },
                    {
                        item:'off',
                        value:'下架'
                    }
                ],
                ids: [],
                fileList: [],
                multipleSelection: []
            }
        },
        components: {
            'table-list':() => import('../common/my-table')
        },
        watch:{
        },
        created(){

        },
        mounted() {
            let sessionId = common.getCookie('sessionId');
            this.url = CONSTANT.URL.ORDER.EXPORT+"?sessionId="+sessionId;
        },
        methods: {
            getProvince:function(){
                let url = CONSTANT.URL.COMMON.GETPROVINCELIST,
                    data={}
                common.requestAjax(url,{},data,(res)=>{
                        if(res.status == 200){
                            this.provinceList = res.data.bussData;
                        }
                    }
                )
            },
            getCityList:function(){
                let url = CONSTANT.URL.COMMON.GETCITYLIST+'/'+this.configList.param.provinceCode,
                    data={}
                common.requestAjax(url,{},data,(res)=>{
                        if(res.status == 200){
                            this.cityList = res.data.bussData;
                        }
                    }
                )
            },
            getList(){
                this.$refs.tableList.getList()
            },
            delLevel(id){
                this.$confirm('确定删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let  url = CONSTANT.URL.TALENT.DELETEITEM,
                        param = {id: id}
                    common.requestAjax(url,{},param,(res)=>{
                        if(res.status == 200){
                            this.$message({
                                type: 'success',
                                message:res.msg
                            });
                            this.getList();
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'warning'
                            });
                        }
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            check:function(){
                this.$message({
                    type: 'warning',
                    message: '请先选择订单'
                });

            },
            selectTable(val) {
                this.ids = []
                this.multipleSelection = []
                val.map( item => {
                    this.ids.push(item.id)
                    this.multipleSelection.push(item.id)
                })
            },
            delAll() {
                if (!this.ids.length) {
                    this.$message({
                        type: 'warning',
                        message: '请选择批量删除的记录'
                    });
                    return false;
                }
                this.$confirm('确定删除?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let url = CONSTANT.URL.TALENT.DELETES;
                    common.requestAjax(url, {}, {ids: this.ids}, (res) => {
                        if(res.status == 200){
                            this.$message({
                                type: 'success',
                                message:res.msg
                            });
                            this.getList();
                        }else{
                            this.$message({
                                message: res.msg,
                                type: 'warning'
                            });
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            submitUpload() {
                this.$refs.upload.submit();
            },
            handleRemove(file, fileList) {
                console.log(file, fileList);
            },
            handlePreview(file) {
                console.log(file);
            },
            submitSign(id) {
                let url = CONSTANT.URL.ORDER.CONFIRMSIGN
                common.requestAjax(url, {}, {id: id}, (res) => {
                    if (res.status == 200) {
                        this.$message({
                            type: "success",
                            message: res.msg
                        })
                        this.getList()
                    }
                })
            },
            submitRefund(id) {
                let url = CONSTANT.URL.ORDER.CANREFUND
                common.requestAjax(url, {}, {id: id}, (res) => {
                    if (res.status == 200) {
                        this.$message({
                            type: "success",
                            message: res.msg
                        })
                        this.getList()
                    }
                })
            }
        }
    }
</script>

<style lang="scss">
    .container {
        .wrap-search{
            margin-bottom: 20px;
            .search-item{
                float: left;
                margin-right: 20px;
                margin-top: 20px;
                .el-input,.el-select{
                    width: 180px;
                }
            }
            button{
                float: left;
                margin-top: 20px;
            }
            .search-title{
                display: inline;
                width: 100px;
                height: 36px;
                line-height: 36px;
                text-align: right;
                margin-bottom: 20px;
                margin-right: 10px;
            }
        }
        .el-table__row{
            .cell{
                button{
                    margin-top: 10px;
                }
            }
            video{
                width: 100px;height: auto;
            }
            img.video-img{
                width: 60px;height: 60px;
                cursor: pointer;
                border-radius: 30px;
            }
        }
        .pagination {
            text-align: center;
            width: 80%;
            margin-top: 60px;
        }
        .el-dialog__body{
            img{
                display: block;
                margin: 0 auto;
            }
        }
        .user-num{
            color:#409EFF;
            cursor: pointer;
        }

        .avatar{
            width: 50px!important;
            height: 50px;
            border-radius: 50%;
            -webkit-border-radius: 50%;
        }
    }
</style>
